package com.ccp.dev.qbdms.service;

import com.ccp.dev.core.basic.base.BaseService;
import com.ccp.dev.core.basic.web.query.QueryFilter;
import com.ccp.dev.core.poi.excel.Excel;
import com.ccp.dev.core.util.BeanUtils;
import com.ccp.dev.qbdms.dao.WRewardsMoneyAllocationDao;
import com.ccp.dev.qbdms.model.WQbdCalRewandpuns;
import com.ccp.dev.qbdms.model.WQbdFlightJczb;
import com.ccp.dev.qbdms.model.WRewardsMoneyAllocation;
import com.ccp.dev.qbdms.util.ProjectUUIDUtils;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 奖惩金额分配表
 *
 * @author hw
 * @date 2020-05-25 15:16:44
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class WRewardsMoneyAllocationService extends BaseService<WRewardsMoneyAllocation> {

    @Resource
    private WRewardsMoneyAllocationDao dao;

    public HSSFWorkbook exportExcel(Excel excel, QueryFilter queryFilter){
        List<WRewardsMoneyAllocation> dataList = this.dao.queryAll(queryFilter);
        int startRow = 1;
        //给每一个单元格赋值
        for (WRewardsMoneyAllocation data : dataList) {
            excel.cell(startRow, 0).value(data.getId());
            //excel.cell(startRow, 1).value(data.getMc());
            //可在赋值时，根据需求进行格式化
            //excel.cell(startRow, 2).value(DateFormatUtil.formatDate(data.getRq()));
            //excel.cell(startRow, 3).value(data.getSj());
            //excel.cell(startRow, 4).value(data.getTenantId());
            startRow++;
        }
        return excel.getWorkBook();
    }

    public List<WRewardsMoneyAllocation> getListByRefId(String refId) {
        return dao.getListByRefId(refId);
    }
    public List<WQbdFlightJczb> getListByRefIdJH(String refId) {
        return dao.getListByRefIdJH(refId);
    }

    /**
     * 批量添加奖惩金额分配信息
     * @param wRewardsMoneyAllocationList 奖惩金额分配信息
     * @param refId 飞行试验奖惩项目主键
     * @return
     */
    public int addList(List<WRewardsMoneyAllocation> wRewardsMoneyAllocationList,String refId){
        for (WRewardsMoneyAllocation wRewardsMoneyAllocation:wRewardsMoneyAllocationList) {
            wRewardsMoneyAllocation.setId(ProjectUUIDUtils.getUUIDFor32());
            wRewardsMoneyAllocation.setRefId(refId);
        }
        return super.addList(wRewardsMoneyAllocationList);
    }

    /**
     * 修改奖惩金额分配信息-->删除旧数据后再重新添加新数据
     * @param wRewardsMoneyAllocationList
     * @param refId
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public int updateAndAdd(List<WRewardsMoneyAllocation> wRewardsMoneyAllocationList,String refId){
        dao.delByRefId(refId);
        if(BeanUtils.isNotEmpty(wRewardsMoneyAllocationList)){
            for (WRewardsMoneyAllocation wRewardsMoneyAllocation:wRewardsMoneyAllocationList) {
                wRewardsMoneyAllocation.setId(ProjectUUIDUtils.getUUIDFor32());
                wRewardsMoneyAllocation.setRefId(refId);
            }
            return super.addList(wRewardsMoneyAllocationList);
        }
        return 0;
    }

    public List<WRewardsMoneyAllocation> getListByRefIdBS(String fxsyxmId) {
        return  dao.getListByRefIdBS(fxsyxmId);
    }
}
